package org.example.controller;

import org.example.cache.RedisUtil;
import org.example.domain.Result;
import org.example.dto.CounterDto;
import org.example.service.CounterService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @FileName CounterController
 * @Description 计数服务
 * @Author coderfun
 * @selfDesc coding in fun
 * @date 2024-11-02
 **/
@RestController
@RequestMapping("/counter")
public class CounterController {

    @Autowired
    private CounterService counterService;
    private static final Logger logger = LoggerFactory.getLogger(CounterController.class);

    @PostMapping("/add")
    public Result add(@RequestBody CounterDto counterDto) {
        boolean status = counterService.add(counterDto);
        return Result.success(status ? "success" : "fail");
    }

    @PostMapping("/sub")
    public Result sub(@RequestBody CounterDto counterDto) {
        boolean status = counterService.sub(counterDto);
        return Result.success(status ? "success" : "fail");
    }

    @PostMapping("/select")
    public Result select(@RequestBody CounterDto counterDto) {
        Integer count = counterService.select(counterDto);
        return Result.success(count);
    }
}
